package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("添加图书");
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入书名");
        String name=scan.nextLine();
        System.out.println("请输入作者");
        String author=scan.nextLine();
        System.out.println("请输入类型");
        String type=scan.nextLine();
        System.out.println("请输入价格");
        int price=scan.nextInt();
        int size=bookList.getSize();
        for(int i=0;i<size;i++){
            Book book=bookList.getBooks(i);
            if(book.getName().equals(name)){
                System.out.println("新增失败，书已存在");
                return ;
            }
        }
        Book books=new Book(name,author,price,type);
        bookList.setBooks(size,books);
        bookList.setSize(size+1);
        System.out.println("新增成功");
    }
}
